package com.lifang.imgsoa.houseimagefile.service;

import java.awt.image.ImageObserver;
import java.util.UUID;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.lifang.imgsoa.houseimagefile.controller.HouseImageFileController;
import com.lifang.imgsoa.model.ImageKeyObject;
import com.lifang.imgsoa.qiniu.MyRet;
import com.lifang.imgsoa.qiniu.QNUtil;


@Service
public class HuigouImageService
{
    
    private Logger logger = LoggerFactory.getLogger(HouseImageFileController.class);
    
    private final String domain = "http://7xkwec.com1.z0.glb.clouddn.com";
    
    @Autowired
    private QNUtil quutil;
    
    public String uploadSingleImage(byte[] data)
    {
        
        String key = UUID.randomUUID().toString().replace("-", "");
        try
        {
            MyRet ret =  quutil.upload(data, key);
        }
        catch (Exception e)
        {
            logger.info("图片上传！");
            e.printStackTrace();
            return "";
        }
        return key;
    }
    
    public ImageKeyObject getImageKeyObject(String key)
    {
        ImageKeyObject object = new ImageKeyObject();
        object.setWater_large(domain + "/" + key + "_large");
        object.setWater_large(domain + "/" + key + "_middle");
        object.setWater_large(domain + "/" + key + "_little");
        return object;
    }
    
    public static void main(String[] args)
    {
        UUID uuid = UUID.randomUUID();
        System.out.println(uuid.toString().replace("-", ""));
    }
}
